package net.bac.sbe.web.sonar.server;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import net.bac.sbe.web.sonar.client.ApplicationMaintenanceService;
import net.bac.sbe.web.sonar.client.view.RepositoryView;
import net.bac.sbe.web.sonar.server.dev.utils.xml.applications.ApplicationsConfig;
import net.bac.sbe.web.sonar.server.dev.utils.xml.applications.RepositoryType;

public class ApplicationMaintenanceServiceImpl extends RemoteServiceServlet implements
		ApplicationMaintenanceService {

	/**
	 *
	 */
	private static final long serialVersionUID = -1309115330054443880L;

	@Override
	public boolean insertApplication(RepositoryView repositoryView) {
		return ApplicationsConfig.getInstance().addRepository(repositoryView);
	}

	@Override
	public boolean deleteApplication(String repositoryName) {
		return ApplicationsConfig.getInstance().deleteRepository(repositoryName);
	}

	public List<String> getApplications() {
		List<String> result = new ArrayList<String>();
		for (RepositoryType repType : ApplicationsConfig.getInstance().getRepositories()) {
			result.add(repType.getName());
		}
		return result;
	}

}
